package com.xyy.controller;

import com.xyy.common.Result;
import com.xyy.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;

/**
 * 邮箱验证控制器
 */
@Slf4j
@RestController
@RequestMapping("/email")
public class EmailController {

    @Autowired
    private UserService userService;

    /**
     * 发送注册邮箱验证码
     */
    @PostMapping("/send-register-code")
    public Result<String> sendRegisterCode(@RequestParam @Email @NotBlank String email) {
        try {
            userService.sendRegisterEmailCode(email);
            return Result.success("验证码已发送，请注意查收");
        } catch (Exception e) {
            log.error("发送注册验证码失败", e);
            return Result.error(e.getMessage());
        }
    }

    /**
     * 发送密码重置邮箱验证码
     */
    @PostMapping("/send-reset-code")
    public Result<String> sendResetCode(@RequestParam @Email @NotBlank String email) {
        try {
            userService.sendEmailCode(email);
            return Result.success("验证码已发送，请注意查收");
        } catch (Exception e) {
            log.error("发送密码重置验证码失败", e);
            return Result.error(e.getMessage());
        }
    }
} 